<?php 
 //Conexion a la BD
 mysql_connect("localhost", "root", "") or die(mysql_error());
 mysql_select_db("posada") or die(mysql_error()); 
 
 //regresa el expediente solicitado
 function getExpediente($expId) {
  $query = "SELECT * FROM DatosGenerales WHERE Expediente = $expId";
  // Get all the data from the "example" table
  $result = mysql_query($query);
  echo "<table border='1'>";
  echo "<tr> <th>Exp#</th><th>Entrada</th><th>Nombre</th>
  <th>Lugar Nac.</th> <th>Fecha Nac.</th> <th>Escolaridad</th> 
  <th>Domicilio</th> <th>Ciudad</th> <th>Telefono</th>
  <th>Diagnostico</th> <th>Tratamiento</th><th>Antecedentes</th>
  <th>Apoyos</th> <th>Motivo Visita</th> <th>Foto</th> </tr>";
  // keeps getting the next row until there are no more to get
  while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>"; 
	echo $row['Expediente'];
	echo "</td><td>";
	echo $row['FechaEntrevista'];
	echo "</td><td>";
	echo $row['NombreCompleto'];
	echo "</td><td>";
	echo $row['LugarNacimiento'];
	echo "</td><td>";
	echo $row['FechaNacimiento'];
	echo "</td><td>";
	echo $row['Escolaridad'];
	echo "</td><td>";
	echo $row['Domicilio'];
	echo "</td><td>";
	echo $row['Ciudad'];
	echo "</td><td>";
	echo $row['Telefono'];
	echo "</td><td>";
	echo $row['DiagnosticoMedico'];
	echo "</td><td>";
	echo $row['Tratamiento'];
	echo "</td><td>";
	echo $row['Antecedentes'];
	echo "</td><td>";
	echo $row['ApoyadoPor'];
	echo "</td><td>";
	echo $row['RazonDeVisita'];
	echo "</td><td>";
	echo $row['NombreFoto'];
	echo "</td></tr>"; 
  } 
  echo "</table>";
 }

 //Regresa todos los expedientes disponibles
 function getTodosExpediente() {
  $query = "SELECT * FROM DatosGenerales";
  // Get all the data from the "example" table
  $result = mysql_query($query); 
  
  echo "<table border='1'>";
  echo "<tr> <th>Exp#</th><th>Entrada</th><th>Nombre</th>
  <th>Lugar Nac.</th> <th>Fecha Nac.</th> <th>Escolaridad</th> 
  <th>Domicilio</th> <th>Ciudad</th> <th>Telefono</th>
  <th>Diagnostico</th> <th>Tratamiento</th><th>Antecedentes</th>
  <th>Apoyos</th> <th>Motivo Visita</th> <th>Foto</th> </tr>";
  // keeps getting the next row until there are no more to get
  while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>"; 
	echo $row['Expediente'];
	echo "</td><td>";
	echo $row['FechaEntrevista'];
	echo "</td><td>";
	echo $row['NombreCompleto'];
	echo "</td><td>";
	echo $row['LugarNacimiento'];
	echo "</td><td>";
	echo $row['FechaNacimiento'];
	echo "</td><td>";
	echo $row['Escolaridad'];
	echo "</td><td>";
	echo $row['Domicilio'];
	echo "</td><td>";
	echo $row['Ciudad'];
	echo "</td><td>";
	echo $row['Telefono'];
	echo "</td><td>";
	echo $row['DiagnosticoMedico'];
	echo "</td><td>";
	echo $row['Tratamiento'];
	echo "</td><td>";
	echo $row['Antecedentes'];
	echo "</td><td>";
	echo $row['ApoyadoPor'];
	echo "</td><td>";
	echo $row['RazonDeVisita'];
	echo "</td><td>";
	echo $row['NombreFoto'];
	echo "</td></tr>";  
 }
  echo "</table>";
 }
 
  //Regresa todos los expedientes disponibles
 function getTodasEntradasConExpediente() {
  $query = "SELECT * FROM EntradaConExpediente e, Motivo m WHERE e.MotivoID = m.MotivoID";
  // Get all the data from the "example" table
  $result = mysql_query($query); 
  
  echo "<table border='1'>";
  echo "<tr> <th>Entrada#</th><th>Exp#</th><th>Fecha Llegada</th>
  <th>Familiar</th> <th>Edad</th><th>Ingreso</th>
  <th>Subsecuente</th><th>Motivo</th><th>FechaSalida</th></tr>";
  // keeps getting the next row until there are no more to get
  while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>"; 
	echo $row['EntradaID'];
	echo "</td><td>";
	echo $row['Expediente'];
	echo "</td><td>";
	echo $row['FechaLlegada'];
	echo "</td><td>";
	echo $row['FamiliarAcompanante'];
	echo "</td><td>";
	echo $row['Edad'];
	echo "</td><td>";
	echo $row['Ingreso'];
	echo "</td><td>";
	echo $row['Subsecuente'];
	echo "</td><td>";
	echo $row['Motivo'];
	echo "</td><td>";
	echo $row['FechaSalida'];
	echo "</td></tr>";  
 }
  echo "</table>";
 }
 
 function getTodasEntradasSinExpediente() {
  $query = "SELECT * FROM EntradaSinExpediente e, Motivo m WHERE e.MotivoID = m.MotivoID";
  // Get all the data from the "example" table
  $result = mysql_query($query); 
  
  echo "<table border='1'>";
  echo "<tr> <th>Entrada#</th><th>Fecha Llegada</th>
  <th>Nombre</th> <th>Edad</th><th>Municipio</th>
  <th>Estado</th><th>Ingreso</th>
  <th>Subsecuente</th><th>Motivo</th><th>FechaSalida</th></tr>";
  // keeps getting the next row until there are no more to get
  while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>"; 
	echo $row['EntradaID'];
	echo "</td><td>";
	echo $row['FechaLlegada'];
	echo "</td><td>";
	echo $row['NombreCompleto'];
	echo "</td><td>";
	echo $row['Edad'];
	echo "</td><td>";
	echo $row['Municipio'];
	echo "</td><td>";
	echo $row['Estado'];
	echo "</td><td>";
	echo $row['Ingreso'];
	echo "</td><td>";
	echo $row['Subsecuente'];
	echo "</td><td>";
	echo $row['Motivo'];
	echo "</td><td>";
	echo $row['FechaSalida'];
	echo "</td></tr>"; 
 }
  echo "</table>";
 }



 function getTodosSeguimientos() {
  $query = "SELECT * FROM SeguimientoPaciente";
  // Get all the data from the "example" table
  $result = mysql_query($query); 
  
  echo "<table border='1' align='center'>";
  echo "<tr><th>Exp#</th><th>Fecha</th> <th>Informacion</th> </tr>";
  // keeps getting the next row until there are no more to get
  while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>"; 
	echo $row['Expediente'];
	echo "</td><td>";
	echo $row['Date'];
	echo "</td><td>";
	echo $row['Informacion'];
	echo "</td></tr>";  
 }
  echo "</table>";
 }
 
 /*getExpediente(1);
 echo "<br/>";
 echo "<br/>";
 getTodosExpediente();
 echo "<br/>";
 echo "<br/>";
 getTodasEntradasConExpediente();
 echo "<br/>";
 echo "<br/>";
 getTodasEntradasSinExpediente();*/
 
 
 
 ?> 
